package com.taoym.voucher.job.config.quartz;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobDataMap;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;

import java.util.Date;

/**
 * @coder taoym
 * @datetime 2021/6/27 0:53
 * @desc
 */
public class TriggerComponent {

    /**
     * @coder taoym
     * @datetime 2021/7/1 22:37
     * @desc 触发器
     */
    public static Trigger cronTrigger(String cron, JobDataMap jobDataMap) {
        return TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule(cron))
                .usingJobData(jobDataMap)
                .build();
    }

    /**
     * @coder taoym
     * @datetime 2021/7/1 22:37
     * @desc 触发器
     */
    public static Trigger cronTrigger(String cron, JobDataMap jobDataMap, String jobName, String group) {
        return TriggerBuilder.newTrigger()
                .withIdentity(jobName, group)
                .withSchedule(CronScheduleBuilder.cronSchedule(cron))
                .usingJobData(jobDataMap)
                .build();
    }
}
